/*
 * DOMCountElement.java
 *
 * Created on 26 ตุลาคม 2550, 22:01 น.
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package anything;

import org.w3c.dom.*;
import javax.xml.parsers.*;
import java.io.*;

/**
 *
 * @author User
 */
public class DOMCountElement {
  
  /** Creates a new instance of DOMCountElement */
  public DOMCountElement() {
  }
  
  public static void main(String[] args) {
    try {
      File file = new File("res/test/Employee-Detail.xml");
      if(file.exists()) {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        //Create the builder and parse the file
        Document doc = factory.newDocumentBuilder().parse(file);
        System.out.println("File name: "+file.getName());
        NodeList nodes = doc.getElementsByTagName("Emp_Name");
        System.out.println("XML Document contains tag <Emp_Name> "+nodes.getLength()+" elements.");
      }
      else
        System.out.println("File not found.");
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
}
